Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coa

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coa

Command-Option-Argument: Yet another parser for command line options.

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.1M
decreased by-3.43%
Maintainers
2
Weekly downloads
 
Created

What is coa?

The coa npm package is a powerful command-line option parser that helps you build command-line applications by defining commands, options, and arguments in a declarative way. It provides a fluent API to make the definition of command-line interfaces easy and readable.

What are coa's main functionalities?

Command definition and execution

This code sample demonstrates how to define a command-line application with a version option and a subcommand. The application will display the version when the '--version' flag is used and will execute a subcommand when 'subcommand' is invoked.

const coa = require('coa');

coa.Cmd()
  .name('app')
  .title('My awesome command line app')
  .helpful()
  .opt()
      .name('version')
      .title('Show version')
      .short('v')
      .long('version')
      .flag()
      .act((opts) => console.log('v1.0.0'))
      .end()
  .cmd()
      .name('subcommand')
      .title('A subcommand example')
      .helpful()
      .act((opts, args) => console.log('Subcommand executed'))
      .end()
  .run(process.argv.slice(2));

Argument parsing

This code sample shows how to define a required argument for a command-line application. The application expects an input file as an argument and will print the name of the input file when the application is run.

const coa = require('coa');

coa.Cmd()
  .name('app')
  .title('My awesome command line app')
  .helpful()
  .arg()
      .name('input')
      .title('Input file')
      .req()
      .end()
  .act((opts, args) => console.log(`Input file: ${args.input}`))
  .run(process.argv.slice(2));

Option parsing

This code sample illustrates how to define an option for a command-line application. The application allows the user to specify an output file using either '-o' or '--output' flags and will print the name of the output file when the application is run.

const coa = require('coa');

coa.Cmd()
  .name('app')
  .title('My awesome command line app')
  .helpful()
  .opt()
      .name('output')
      .title('Output file')
      .short('o')
      .long('output')
      .end()
  .act((opts, args) => console.log(`Output file: ${opts.output}`))
  .run(process.argv.slice(2));

Other packages similar to coa

FAQs

Package last updated on 27 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc